package Group9.TodoManager.View;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JPanel;
import javax.swing.Timer;

import Group9.TodoManager.Settings;

/**
 * This is a custom date and time display for the application
 * It will be placed in the upper right part of the mainUI.
 * @author Rupesh
 * @author volkan cambazoglu
 */
public class CustomDateTimeDisplay extends JPanel implements ActionListener {
	
    DateFormat format = new SimpleDateFormat("ss");
    Timer timer;

    /**
     * Starts the timer
     */
    public void Start() {
        timer = new Timer(1000, this);
        timer.start();
    }

    /**
     * When action is performed, repaint the component
     * @param e event
     */
    public void actionPerformed(ActionEvent e) {
        repaint();
    }

    /**
     * Paint the component
     * @param g the graphics to be painted
     */
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Font font = new Font("serif", Font.BOLD, 14);
        g.setFont(font);
        g.drawString(
        	Settings.getCurrentResourceBundle().getString("CurrentDate") + 
        	": " + getCurrentDateTime(), 30, 20);
    }

    /**
     * Getter method for current date and time
     * @return currentDateTime
     */
    public String getCurrentDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy, E, hh:mm:ss");
        return dateFormat.format(new Date());        
    }

    /**
     * Getter method for preferred size
     * @return dimension preferred size
     */
    @Override
        public Dimension getPreferredSize() {
        return new Dimension(320,25);
    }
}
